package main

import (
	"encoding/json"
	"fmt"
	"gitee.com/hlwqds/rabitmqTest/config"
	"gitee.com/hlwqds/rabitmqTest/log"
	"gitee.com/hlwqds/rabitmqTest/rabbitmqInAction/concurrenceTask/concurrenceConfig"
	message "gitee.com/hlwqds/rabitmqTest/rabbitmqInAction/concurrenceTask/concurrenceTaskMessage"
	"github.com/streadway/amqp"
)

func main(){
	conn, err := amqp.Dial(config.GenURLFromConfig())
	log.FailOnError(err, "amqp.Dial err")
	ch, err := conn.Channel()
	log.FailOnError(err, "conn.Channel err")
	ch.ExchangeDeclare(
		concurrenceConfig.ConcurrenceExchange,
		"fanout",
		false,
		false,
		false,
		false,
		nil,
		)

	messageMeta := message.Message{
		ImageId: 1,
		UserId: 1,
		ImagePath: "/home/root/test.svg",
	}
	messageJson, err := json.Marshal(messageMeta)
	log.FailOnError(err, "json.Marshal error")
	fmt.Printf("prepare to send message: %s\n", messageJson)

	ch.Publish(
		concurrenceConfig.ConcurrenceExchange,
		"",
		false,
		false,
		amqp.Publishing{
			ContentType: "application/json",
			Body: messageJson,
		})
}